package cn.edu.tju.scs.network.ftp.utils;

/**
 * Created by catold on 16/1/7.
 */
public class CommandLine {
    public static final String SPLIT = " ";
    public String source;
    public String cmd;
    public String[] args;

    /**
     * 从一行命令中构建对象
     * @param line
     */
    public static CommandLine buildFromLine(String line) {
        CommandLine commandLine = new CommandLine();
        commandLine.source = line;

        String[] strs = line.split(SPLIT);
        commandLine.cmd = strs[0];
        if (strs.length - 1 <= 0) {
            return commandLine;
        }
        commandLine.args = new String[strs.length - 1];
        for(int i = 1; i < strs.length; i++) {
            commandLine.args[i - 1] = strs[i];
        }
        return commandLine;
    }

    public boolean isCmd(String cmd){
        return this.cmd.equals(cmd);
    }

    public boolean isCmd(CmdEnum cmdEnum){
        return this.cmd.equals(cmdEnum.toString().toLowerCase());
    }
}
